package com.yssw.client.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yssw.common.annotation.Log;
import com.yssw.common.core.controller.BaseController;
import com.yssw.common.core.domain.AjaxResult;
import com.yssw.common.enums.BusinessType;
import com.yssw.client.domain.DrinkWaterLog;
import com.yssw.client.service.IDrinkWaterLogService;
import com.yssw.common.utils.poi.ExcelUtil;
import com.yssw.common.core.page.TableDataInfo;

/**
 * 用水记录Controller
 *
 * @author yssw
 * @date 2023-04-03
 */
@RestController
@RequestMapping("/client/drinkLog")
public class DrinkWaterLogController extends BaseController {
    @Autowired
    private IDrinkWaterLogService drinkWaterLogService;

    /**
     * 查询用水记录列表
     */
    @PreAuthorize("@ss.hasPermi('client:drinkLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrinkWaterLog drinkWaterLog) {
        startPage();
        List<DrinkWaterLog> list = drinkWaterLogService.selectDrinkWaterLogList(drinkWaterLog);
        return getDataTable(list);
    }

    /**
     * 导出用水记录列表
     */
    @PreAuthorize("@ss.hasPermi('client:drinkLog:export')")
    @Log(title = "用水记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrinkWaterLog drinkWaterLog) {
        List<DrinkWaterLog> list = drinkWaterLogService.selectDrinkWaterLogList(drinkWaterLog);
        ExcelUtil<DrinkWaterLog> util = new ExcelUtil<DrinkWaterLog>(DrinkWaterLog.class);
        util.exportExcel(response, list, "用水记录数据");
    }

    /**
     * 获取用水记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('client:drinkLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(drinkWaterLogService.selectDrinkWaterLogById(id));
    }

    /**
     * 新增用水记录
     */
    @PreAuthorize("@ss.hasPermi('client:drinkLog:add')")
    @Log(title = "用水记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrinkWaterLog drinkWaterLog) {
        return toAjax(drinkWaterLogService.insertDrinkWaterLog(drinkWaterLog));
    }

    /**
     * 修改用水记录
     */
    @PreAuthorize("@ss.hasPermi('client:drinkLog:edit')")
    @Log(title = "用水记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrinkWaterLog drinkWaterLog) {
        return toAjax(drinkWaterLogService.updateDrinkWaterLog(drinkWaterLog));
    }

    /**
     * 删除用水记录
     */
    @PreAuthorize("@ss.hasPermi('client:drinkLog:remove')")
    @Log(title = "用水记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(drinkWaterLogService.deleteDrinkWaterLogByIds(ids));
    }
}
